<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/s_l/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/s_l/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/s_l/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/s_l/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/s_l/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/s_l/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/s_l/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Java多线程,">










<meta name="description" content="多线程是Java开发中的高级开发模块，熟悉多线程的开发特性，可以帮助我们开发出真正可以支持大量用户使用的程序，而不仅仅是一个玩具">
<meta name="keywords" content="Java多线程">
<meta property="og:type" content="article">
<meta property="og:title" content="线程的四种创建方式">
<meta property="og:url" content="http://yoursite.com/2019/05/06/线程的四种创建方式/index.html">
<meta property="og:site_name" content="S.L">
<meta property="og:description" content="多线程是Java开发中的高级开发模块，熟悉多线程的开发特性，可以帮助我们开发出真正可以支持大量用户使用的程序，而不仅仅是一个玩具">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-05-09T11:07:58.871Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="线程的四种创建方式">
<meta name="twitter:description" content="多线程是Java开发中的高级开发模块，熟悉多线程的开发特性，可以帮助我们开发出真正可以支持大量用户使用的程序，而不仅仅是一个玩具">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/s_l/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/05/06/线程的四种创建方式/">





  <title>线程的四种创建方式 | S.L</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/s_l/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">S.L</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">记录学习过程中的点滴</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/s_l/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/s_l/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/s_l/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/s_l/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/s_l/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/s_l/2019/05/06/线程的四种创建方式/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏立鹏">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/s_l/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="S.L">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">线程的四种创建方式</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-05-06T20:03:01+08:00">
                2019-05-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  4 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote>
<p>多线程是Java开发中的高级开发模块，熟悉多线程的开发特性，可以帮助我们开发出真正可以支持大量用户使用的程序，而不仅仅是一个玩具</p>
</blockquote>
<a id="more"></a>
<h3 id="通过继承来创建一个多线程"><a href="#通过继承来创建一个多线程" class="headerlink" title="通过继承来创建一个多线程"></a>通过继承来创建一个多线程</h3><p>1)  定义子类继承Thread类。<br>2)  子类中重写Thread类中的run方法。<br>3)  创建Thread子类对象，即创建了线程对象。<br>4)  调用线程对象start方法：启动线程，调用run方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.创建一个继承于Thread类的子类</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">NumberThread</span> <span class="keyword">extends</span> <span class="title">Thread</span></span>&#123;</span><br><span class="line">	</span><br><span class="line">	<span class="comment">//2.重写run()</span></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span> </span>&#123;</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>;i &lt;= <span class="number">100</span>;i++)&#123;</span><br><span class="line">			<span class="keyword">if</span>(i % <span class="number">2</span> == <span class="number">0</span>)&#123;</span><br><span class="line">				System.out.println(getName() + <span class="string">":"</span> + i);</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ThreadTest</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		<span class="comment">//3.创建Thread类的子类的对象</span></span><br><span class="line">		NumberThread t1 = <span class="keyword">new</span> NumberThread();</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//4.通过此对象，调用start()</span></span><br><span class="line">		t1.start();</span><br><span class="line">		<span class="comment">//问题：可否直接调用run(),替换start()来执行分线程? </span></span><br><span class="line">        <span class="comment">//t1.run();如果这么执行得到还是当前线程</span></span><br><span class="line">	</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//正确的：</span></span><br><span class="line">		NumberThread t2 = <span class="keyword">new</span> NumberThread();</span><br><span class="line">		t2.start();</span><br><span class="line">		</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>;i &lt;= <span class="number">100</span>;i++)&#123;</span><br><span class="line">			<span class="keyword">if</span>(i % <span class="number">2</span> == <span class="number">0</span>)&#123;</span><br><span class="line">				System.out.println(Thread.currentThread().getName() + <span class="string">":"</span> + i + *****<span class="string">");</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&#125;</span></span><br><span class="line"><span class="string">	&#125;</span></span><br><span class="line"><span class="string">&#125;</span></span><br></pre></td></tr></table></figure>
<h3 id="通过实现Runnable来创建一个多线程"><a href="#通过实现Runnable来创建一个多线程" class="headerlink" title="通过实现Runnable来创建一个多线程"></a>通过实现Runnable来创建一个多线程</h3><p>1).提供一个实现了Runnable接口的类<br>2).实现接口中的run():将此线程要执行的操作声明在此方法中<br>3).创建一个Runnable接口的实现类的对象<br>4).将此对象作为参数，传递到Thread类的构造器中，创建Thread类的对象<br>5).通过Thread类的对象调用start():①启动线程 ②调用当前线程的run() —&gt;当前线程的run()中调用了Runnable实现类的run()<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.提供一个实现了Runnable接口的类</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">NumThread</span> <span class="keyword">implements</span> <span class="title">Runnable</span></span>&#123;</span><br><span class="line">	<span class="comment">//2.实现接口中的run()</span></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span> </span>&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>;i &lt;= <span class="number">100</span>;i++)&#123;</span><br><span class="line">			<span class="keyword">if</span>(i % <span class="number">2</span> == <span class="number">0</span>)&#123;</span><br><span class="line">				System.out.println(Thread.currentThread().getName() + <span class="string">":"</span> + i);</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">		</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ThreadTest1</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		<span class="comment">//3.创建一个Runnable接口的实现类的对象</span></span><br><span class="line">		NumThread num = <span class="keyword">new</span> NumThread();</span><br><span class="line">		<span class="comment">//4.将此对象作为参数，传递到Thread类的构造器中，创建Thread类的对象</span></span><br><span class="line">		Thread t1 = <span class="keyword">new</span> Thread(num);</span><br><span class="line">		Thread t2 = <span class="keyword">new</span> Thread(num);</span><br><span class="line">		<span class="comment">//5.通过Thread类的对象调用start()</span></span><br><span class="line">		t1.start();</span><br><span class="line">		t2.start();</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h3 id="通过实现Callable来创建一个多线程"><a href="#通过实现Callable来创建一个多线程" class="headerlink" title="通过实现Callable来创建一个多线程"></a>通过实现Callable来创建一个多线程</h3><p>1)Callable接口是JDK1.5以后提出来的，是对Runnable接口的一个升级，可以拥有返回值</p>
<table>
<thead>
<tr>
<th>区别</th>
<th>Callable</th>
<th>Runnable</th>
</tr>
</thead>
<tbody>
<tr>
<td>是否有返回值</td>
<td>有</td>
<td>没有</td>
</tr>
<tr>
<td>是否可以抛出异常</td>
<td>可以</td>
<td>不可以</td>
</tr>
<tr>
<td>是否支持泛型</td>
<td>支持</td>
<td>不支持</td>
</tr>
</tbody>
</table>
<p>代码实现：<br>和Runnable接口不同的是，Callable接口需重定义的是call()<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">NumberPrint</span> <span class="keyword">implements</span> <span class="title">Callable</span></span>&#123;</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Object <span class="title">call</span><span class="params">()</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">		<span class="keyword">int</span> sum = <span class="number">0</span>;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>;i &lt;= <span class="number">100</span>;i++)&#123;</span><br><span class="line">			<span class="keyword">if</span>(i % <span class="number">2</span> == <span class="number">0</span>)&#123;</span><br><span class="line">				System.out.println(i);</span><br><span class="line">				sum += i;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> sum;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>Callable接口的使用要稍微复杂一些，需要借助FutureTask来协助创建线程和获取方法的返回值</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span>  </span>&#123;</span><br><span class="line">		</span><br><span class="line">		NumberPrint num = <span class="keyword">new</span> NumberPrint();</span><br><span class="line">		</span><br><span class="line">		FutureTask task = <span class="keyword">new</span> FutureTask(num);</span><br><span class="line">		</span><br><span class="line">		Thread t1 = <span class="keyword">new</span> Thread(task);</span><br><span class="line">		</span><br><span class="line">		t1.start();</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//需要借助于FutureTask来获取call方法的返回值</span></span><br><span class="line">		<span class="keyword">try</span> &#123;</span><br><span class="line">			Object sum = task.get();</span><br><span class="line">			System.out.println(sum);</span><br><span class="line">		&#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>
<h3 id="通过线程池来创建一个多线程"><a href="#通过线程池来创建一个多线程" class="headerlink" title="通过线程池来创建一个多线程"></a>通过线程池来创建一个多线程</h3><p>线程池方式应该是在项目中使用线程最推荐的方式，因为其可以对线程进行一个良好的管理，而且可以节约资源。<br>使用线程池的好处：</p>
<ul>
<li>提高响应速度（减少了创建新线程的时间）</li>
<li>降低资源消耗（重复利用线程池中线程，不需要每次都创建）</li>
<li>便于线程管理<br>JDK 5.0起提供了线程池相关API：ExecutorService 和 Executors<br>ExecutorService：真正的线程池接口。常见子类ThreadPoolExecutor<br>示例代码：使用子类ThreadPoolExecutor创建线程池<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">	<span class="comment">// 1.调用Executors的newFixedThreadPool(),返回指定线程数量的ExecutorService</span></span><br><span class="line">	ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(<span class="number">10</span>);</span><br><span class="line">	<span class="comment">//设置管理参数</span></span><br><span class="line">	pool.setMaximumPoolSize(<span class="number">20</span>);</span><br><span class="line">	<span class="comment">// 2.将Runnable实现类的对象作为形参传递给ExecutorService的execute()方法中，开启线程</span></span><br><span class="line">	<span class="comment">// 并执行相关的run()</span></span><br><span class="line">	pool.execute(<span class="keyword">new</span> MyThread());</span><br><span class="line">	pool.execute(<span class="keyword">new</span> MyThread());</span><br><span class="line">	pool.execute(<span class="keyword">new</span> MyThread());</span><br><span class="line">	</span><br><span class="line">	<span class="comment">// 3.结束线程的使用</span></span><br><span class="line">	pool.shutdown();</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/s_l/tags/Java多线程/" rel="tag"># Java多线程</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/s_l/2019/04/18/面向对象思想的概述-封装/" rel="next" title="面向对象思想概述-封装">
                <i class="fa fa-chevron-left"></i> 面向对象思想概述-封装
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/s_l/2019/05/06/线程间的通信/" rel="prev" title="线程间的通信">
                线程间的通信 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">苏立鹏</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/s_l/archives/">
              
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://gitee.com/www.86740.com/projects" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#通过继承来创建一个多线程"><span class="nav-number">1.</span> <span class="nav-text">通过继承来创建一个多线程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#通过实现Runnable来创建一个多线程"><span class="nav-number">2.</span> <span class="nav-text">通过实现Runnable来创建一个多线程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#通过实现Callable来创建一个多线程"><span class="nav-number">3.</span> <span class="nav-text">通过实现Callable来创建一个多线程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#通过线程池来创建一个多线程"><span class="nav-number">4.</span> <span class="nav-text">通过线程池来创建一个多线程</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">苏立鹏</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/s_l/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/s_l/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/s_l/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/s_l/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/s_l/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/s_l/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/s_l/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/s_l/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/s_l/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/s_l/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/s_l/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/s_l/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/s_l/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
